<template>
   <div>
      <ForumSystemPostsVue class="GradientAnimation" v-if="postsInfo._id" :systemInfo="systemInfo"
         :postsInfo="postsInfo" />
      <div v-else class="cnyzs-posts-error">
         <p>404</p>
      </div>
   </div>
</template>
<script lang="ts" setup >
import ForumSystemPostsVue from "./ForumSystemPosts.vue"
const { posts } = useRoute().params

// 获取帖子详情
// 全系统同一个接口获取详情
// 后端需要验证是否登陆用户访问，处理结果都不一样
const systemInfo: any = ref({})
const postsInfo: any = ref({})
const status = ref(false)
const getpostsinfo = async () => {
   const res: any = await cnyzsRequest('/api/cnyzs-system-posts/FrontPostsinfo/' + posts, { method: 'GET' })
   // 返回成功
   if (res.status === 200) {
      systemInfo.value = res.data.systemInfo
      postsInfo.value = res.data.postsInfo
      return
   }
   status.value = true
   // // 审核中
   // if (res.status === 202) {
   // }
   // // 已驳回
   // if (res.status === 403) {
   // }
   // // 不存在/已删除
   // if (res.status === 404) {
   // }
}
await getpostsinfo()

// 页头处理
useHead({
   title: computed(() => {
      if (postsInfo.value._id) {
         return postsInfo.value.postsTitle || postsInfo.value.postsContent.slice(0, 50)
      } else {
         return '404'
      }
   }),
   meta: [
      {
         name: 'keywords',
         content: computed(() => {
            if (postsInfo.value._id) {
               return postsInfo.value.postsTitle || postsInfo.value.postsContent.slice(0, 50)
            } else {
               return '404'
            }
         })
      },
      {
         name: 'description',
         content: computed(() => {
            if (postsInfo.value._id) {
               return postsInfo.value.postsContent.slice(0, 150)
            } else {
               return '404'
            }
         })
      }
   ]
})


</script>
<style lang="scss" scoped>
.cnyzs-posts-error {
   width: var(--aoir-m-width);
   margin: 0 auto;
   min-height: 600px;
   display: flex;
   justify-content: center;
   align-items: center;

   p {
      font-size: 150px;
      font-weight: 900;
   }
}
</style>